package com.david.flowable.config;

import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class ProcessEngineConfig {
    @Value("${spring.datasource.url}")
    private String url;
    @Value("${spring.datasource.driver-class-name}")
    private String driverClassname;
    @Value("${spring.datasource.username}")
    private String username;
    @Value("${spring.datasource.password}")
    private String password;

    @Bean(name="processEngine")
    public ProcessEngine initProcessEngine() {
        log.info("=====================ProcessEngineStart======================");
        ProcessEngineConfiguration cfg = null;
        try {
            cfg = new StandaloneProcessEngineConfiguration()
                    .setJdbcUrl("jdbc:mysql://23kv52kb9215.vicp.fun:31465/industry?serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true")
                    .setJdbcUsername(username)
                    .setJdbcDriver(driverClassname)
                    .setJdbcPassword(password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        ProcessEngine processEngine = cfg.buildProcessEngine();
        log.info("=====================ProcessEngineEnd======================");
        return processEngine;
    }
}
